<template>
	<view>
		<!-- <u-navbar :is-back="true" :is-fixed="true" title="产品上市简报"></u-navbar> -->
		<!-- Tab navigation -->
		<view class="fixed-top bg-white">
			<view class="px-2 mt-2 pb-2">
				<u-search placeholder="请输入关键字 " height="60" border-color="#8ED0F2" search-icon-color="#8ED0F2"
					bg-color="#fff" v-model="keyword" :action-style="actionStyle" @input="search"></u-search>
			</view>
			<u-gap height="20" bg-color="#f7f7f7"></u-gap>
		</view>
		<scroll-view scroll-y scroll-with-animation style="height: calc(100vh - 0px)" :show-scrollbar="false"
			@scrolltolower="loadMore" @scrolltoupper="refresh">
			<view class="p-2" style="margin-top: 60px">
				<view class="dfex u-lines pb-2" v-for="(item, index) in list">
					<view class="lineHight">
						<view class="text-333333 font-14">{{ item.title || '-' }}</view>
						<view class="text-A0A0A0 font-12 wrap">企业名称：{{ item.agricultureUserId_dictText || '-' }}</view>
						<view class="text-A0A0A0 font-12">产品名称：{{ item.productName || '-' }}</view>
					</view>
					<view class="bg-78AB06 py-1 pl-2 pr-2 rounded-circle font-14 text-white"
						@click="open('tabbar/index/ProductLaunchDetails', item)">查看详情</view>
				</view>
			</view>
			<view v-if="!hasMore && list.length > 0" class="text-center mt-3 mb-3 pb-2">
				<view class="text-muted">没有更多数据了</view>
			</view>
			<view v-else-if="!hasMore && list.length === 0" class="text-center mt-3 mb-3">
				<view class="icon-sousuo1 iconfont text-999999" style="font-size: 55px;"></view>
				<view class="text-999999 font-15">暂时木有内容呀~~</view>
			</view>
			<view v-else class="text-center mt-3 mb-3">
				<view class="btn btn-primary">加载更多</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import $H from '@/common/free-lib/request.js';

export default {
  data() {
    return {
      scrollinto: '',
      keyword: '',
      actionStyle: {
        color: '#8ED0F2',
      },
      list: [],
      form: {
        pageNo: 1,
        pageSize: 10,
        total: 0, // Total records
      },
      hasMore: true, // Whether there is more data to load
      isLoading: false, // Whether data is being loaded
    };
  },
  created() {
    this.getList();
  },
  methods: {
    setDefaultPageConfig() {
      this.form.pageNo = 1;
      this.form.pageSize = 10;
      this.form.total = 0;
      this.hasMore = true;
    },
    open(path, item) {
      uni.navigateTo({
        url: `/pages/${path}?item=${JSON.stringify(item)}&type='Brie'`,
      });
    },
    // Query
    search() {
      if (this.keyword.trim() === '') {
        // If keyword is empty, display original data
        this.isSearching = false;
        this.setDefaultPageConfig();
        this.list = [];
        this.getList();
        return;
      }
      this.setDefaultPageConfig();
      this.list = [];
      this.getList();
    },
   getList() {
       if (this.isLoading) return;
   
       this.isLoading = true;
       $H.get(
           `/basisInform/listingBriefing/down/list`,
           {
               ...this.form,
               title: this.keyword.trim(),
           },
           { token: true }
       )
       .then((res) => {
           if (res.result) {
               if (this.form.pageNo === 1) {
                   this.list = res.result.records || [];
               } else {
                   this.list = this.list.concat(res.result.records || []);
               }
               this.form.total = res.result.total;
               this.hasMore = this.list.length < this.form.total;
           } else {
               // 如果 res.result 为 null，根据实际需求设置界面状态
               if (this.form.pageNo === 1) {
                   this.list = [];
               }
               this.hasMore = false;
           }
           this.isLoading = false;
       })
       .catch(() => {
           this.isLoading = false;
       });
   },

	// 加载更多
	loadMore() {
	
		if (this.form.pageNo * this.form.pageSize >= this.form.total) {
			this.hasMore = false;
			return;
		}
		this.form.pageNo++;
		// 请求数据
		this.getList();
	},
	// 下拉刷新
	refresh() {
		// 重置页码为 1
		this.form.pageNo = 1;
		// 清空数据列表
		this.list = [];
		// 设置标记为有更多数据
		this.hasMore = true;
		// 重新请求数据
		this.getList();
		// 结束下拉刷新动画
		uni.$emit('stopPullDownRefresh');
	},
    // Load more
    loadMore() {
      if (!this.hasMore || this.isLoading) return;

      this.form.pageNo++;
      this.getList();
    },
    // Pull down refresh
    refresh() {
      this.setDefaultPageConfig();
      this.list = [];
      this.getList();
      // End pull down refresh animation
      uni.$emit('stopPullDownRefresh');
    },
  },
};
</script>


<style lang="scss" scoped>
	.tab-scroll {
		width: 100vw;
	}

	.tab-item {
		width: 50%;
		display: inline-block;
		text-align: center;
		padding: 0 10px;
		line-height: 40px;
	}
</style>